﻿#pragma once
#include "XyNet/Global.h"
#include <google/protobuf/message.h>

namespace XyNet
{
	class RpcController;
	class RpcSocketChannel;

	/// rpc服务管理器，用于保存处理具体事务的服务
	class XYNET_API RpcArgument : noncopyable
	{
	protected:
		RpcArgument(shared_ptr<google::protobuf::Message> request,
			shared_ptr<google::protobuf::Message> response)
			: _request(request), _response(response) {}

	public:
		virtual ~RpcArgument() {}

		/// 获取控制器
		inline shared_ptr<RpcController> getController() { return _controller; }
		/// 获取请求
		inline shared_ptr<const google::protobuf::Message> getRequest() const { return _request; }
		/// 获取应答
		inline shared_ptr<google::protobuf::Message> getResponse() { return _response; }

		/// 要保证多态，需要克隆
		virtual shared_ptr<RpcArgument> clone() = 0;
		/// 初始化控制器
		virtual void initializeController(RpcSocketChannel* socketChannel) = 0;

	protected:
		shared_ptr<RpcController> _controller;
		shared_ptr<google::protobuf::Message> _request;
		shared_ptr<google::protobuf::Message> _response;
	};
}